package com.hk.webapp.controller.admin;

import com.hk.webapp.annotations.SkipPermission;
import com.hk.webapp.service.CmsArticleService;
import com.hk.webapp.service.SysRoleService;
import com.hk.webapp.service.SysUserService;
import com.hk.webapp.service.UserService;
import com.hk.webapp.vo.NameValueVo;
import com.hk.webapp.vo.ResultVo;
import com.hk.webapp.service.*;
import com.google.common.collect.Maps;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;

@RestController
@SkipPermission
public class StatisticalController extends AdminBaseController {

    @Resource
    private UserService userService;
    @Resource
    private SysUserService sysUserService;
    @Resource
    private SysRoleService sysRoleService;
    @Resource
    private CmsArticleService cmsArticleService;



    @PostMapping("/Statistical/HomeData")
    public ResultVo homeData(){
        Integer userCount=userService.getCount();
        Integer sysUserCount=sysUserService.getCount();
        Integer articleCount=cmsArticleService.getCount();
        Integer roleCount=sysRoleService.getCount();

        HashMap<String,Object> map= Maps.newHashMap();
        map.put("user",userCount);
        map.put("sysUser",sysUserCount);
        map.put("article",articleCount);
        map.put("role",roleCount);
        return ResultVo.createBySuccessData(map);
    }

    @PostMapping("/Statistical/getUserProvinceCounts")
    public ResultVo getUserProvinceCounts(){
        List<NameValueVo> userProvinceCounts=userService.getUserProvinceCounts();
        return ResultVo.createBySuccessData(userProvinceCounts);
    }



    @PostMapping("/Statistical/GetServerInfo")
    public ResultVo getServerInfo(){
        Properties props=System.getProperties();

        HashMap<String,Object> map=Maps.newHashMap();
        map.put("ContentRootPath",props.getProperty("user.dir"));
        map.put("OperatingSystemArch",props.getProperty("os.arch"));
        map.put("JavaVersion",props.getProperty("java.version"));
        map.put("MachineName",props.getProperty("os.version"));
        map.put("UserDomainName","");
        map.put("UserName",props.getProperty("user.name"));
        map.put("VersionString",props.getProperty("os.name"));
        map.put("WebUseSpace","");
        return ResultVo.createBySuccessData(map);
    }
}
